<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Api {
    public function getPic(){

        $rs=Db::name('pictures')->select();
        return json($rs);
    }
    public function getComment(){
        $pi_id=input("pi_id");
        $rs=Db::name('comments')->where("pi_id",$pi_id)->select();
        return json($rs);
    }
    public function getClub(){

        $rs=Db::name('clubs')->select();
        return json($rs);
    }
   /* public function userLogin.do($username, $userpass, $normal){
         global $conn;  
          
        if($conn) {  
            $result = mysql_query("select username,userpass from clubs");  
            $success = false;  
            while($row = mysql_fetch_array($result)) {  
                if($name == $row['u_name'] && $psd == $row['u_password']) {  
                    $success = true;  
                }  
            }  
            if($normal) {  
                $login_result = array('login_result'=>$success);  
                $json = json_encode($login_result);  
                echo $json;  
            }  
        }  
        return $success;  


        /* $username=input("u_name");
          $userpass=input("u_password");
        $rs=Db::name('users')->where("u_name",$username)->where("u_password",$userpass)->select();
        return json($rs);*/
    public function login(){
    $uname=input('username');
    $upassword=input('password');
    $users=Db::name('user')->where('uname',$uname)->find();
        if ($users)
         {
          if (md5($upassword)==$users['password'])
           {
            return json([
                          'error'=>'0',
                          'uid'=>$users['uid'],
                          'uname'=>$users['uname'],
                          'ugender'=>$users['ugender'],
                          'ubirthdate'=>$users['ubirthdate'],
                          'upic'=>$users['upic'],
                          'uphone'=>$users['uphone'],
                        ]);
          }else{
            
            return json([
                          'error'=>'1',
                          'msg'=>'密码错误',
                              ]);
          }
        }else{
          
          return json([
                          'error'=>'2',
                          'msg'=>'用户不存在',
                       ]);
        }


  }

